package de.ciupka.minesweeper.gamecreator;

import java.awt.Dimension;
import java.util.ArrayList;

public class Gamecreator {

	private int height;
	private int width;
	private int mines;
	
	
	public Gamecreator() {
		height = 9;
		width = 9;
		mines = 10;
	}
	
	public int getHeight() {
		return height;
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getMines() {
		return mines;
	}
	
	public int updateHeight(int height) {
		if(height < 9) {
			this.height = 9;
		} else if(height > 24) {
			this.height = 24;
		} else {
			this.height = height;
		}
		return this.height;
	}

	public int updateWidth(int width) {
		if(width < 9) {
			this.width = 6;
		} else if(width > 30) {
			this.width = 30;
		}
		else {
			this.width = width;
		}
		return this.width;
	}

	public int updateMines(int mines) {
		if(mines < 10) {
			this.mines = 10;
		}
		else if(mines > 668) {
			this.mines = (int) ((width * mines) * 0.9);
		} else {
			this.mines = mines;
		}
		return mines;
	}
	
	public Dimension calculateGameFrameSize() {
		int frameWidth = (this.width + 4) * 25;
		int frameHeight = (this.height + 4) * 25;
		return new Dimension(frameWidth, frameHeight);
	}
	
	public String stringInput(String input) {
		char[] charInput = input.toCharArray();
		StringBuilder string = new StringBuilder();
		for(int i = 0; i < input.length() - 1; i++) {
			try {
				Integer.parseInt(String.valueOf(charInput[i]));
				string.append(charInput[i]);
			} catch(Exception e) {
				break;
			}
		}
		return string.toString();
	}
	
	public void createNewGame() {
		
	}
}
